<%-- 
    Document   : lightEdit
    Created on : Sep 8, 2011, 12:22:19 PM
    Author     : HIEP
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@taglib uri="http://java.fckeditor.net" prefix="fck" %>
<!DOCTYPE html>
<script>
    function validFlight(){
        var name = document.forms["Flights"]["name"].value;
        var departure_time = document.forms["Flights"]["departure_time"].value;
        var arrival_time = document.forms["Flights"]["arrival_time"].value;
        
        if(name == "" || name == null){
            alert("Please enter name of flight!");
            return false;
        }
        if(departure_time == "" || departure_time == null){
            alert("Please enter departure time of flight!");
            return false;
        }
        if(arrival_time == "" || arrival_time == null){
            alert("Please enter arrival time of flight!");
            return false;
        }
        return true;
    } 
</script>

<div id="content" class="roundedBorders">
    <!-- Title -->
    <div id="title" class="b2">
        <h2>Manage Flights</h2>
    </div>
    <!-- Title -->
    <!-- Inner Content -->
    <div id="innerContent">
        <logic:empty name="item">
            <!-- Form -->
            <html:form action="/FlightAction.do?method=add" method="POST" onsubmit="return validFlight();">
                <html:hidden property="" value=""/>
                <div class="fieldset fieldsetBlock active tabs">
                    <div class="header">
                        <h3>Add new flight</h3>
                    </div>
                    <div class="tabs">
                        <fieldset id="fieldset1" >
                            <legend>Post content</legend>
                            <div class="field required">
                                <label>Name</label> 
                                <html:text styleClass="text" name="item" property="name" value=""/>
                                <span class="required-icon tooltip" title=" This field is required, it cannot be blank.">Required</span> 
                            </div>
                            <div class="field required">
                                <label>Departure City</label> 
                                <select name="departure_city">
                                    <c:forEach items="${locationList}" var="loc">
                                        <option value="${loc.id}">${loc.name}</option>
                                    </c:forEach>
                                </select>
                            </div>
                            <div class="field required">
                                <label>Departure Time</label> 
                                <html:text styleClass="text" name="item" property="departure_time" value=""/>
                                <span class="required-icon tooltip" title=" This field is required, it cannot be blank.">Required</span> 
                            </div>
                            <div class="field required">
                                <label>Arrival City</label> 
                                <select name="arrival_city">
                                    <c:forEach items="${locationList}" var="loc">
                                        <option value="${loc.id}">${loc.name}</option>
                                    </c:forEach>
                                </select>
                            </div>
                            <div class="field required">
                                <label>Arrival Time</label> 
                                <html:text styleClass="text" name="item" property="arrival_time" value=""/>
                                <span class="required-icon tooltip" title=" This field is required, it cannot be blank.">Required</span> 
                            </div>
                            <div id="buttom1">
                                <strong>
                                    <html:submit value="Add Flight" styleClass="buttom_form"/>
                                </strong>
                                <strong>    
                                    <html:reset value="Reset" styleClass="buttom_form"/>
                                </strong>
                            </div>
                        </fieldset>
                    </div>
                    <span class="bBR"></span>
                </div>
            </html:form>
            <!-- /Form -->
        </logic:empty>	
        <logic:notEmpty name="item">
            <!-- Form -->
            <html:form action="/FlightAction.do?method=update" method="POST" onsubmit="return validFlight();">
                <html:hidden property="" value=""/>
                <div class="fieldset fieldsetBlock active tabs">
                    <div class="header">
                        <h3>Edit flight</h3>
                    </div>
                    <div class="tabs">
                        <fieldset id="fieldset1" >
                            <legend>Post content</legend>
                            <html:hidden name="item" property="id"/>
                            <div class="field required">
                                <label>Name</label> 
                                <input type="text" class="text" name="name" id="name" value="${item.name}"/> 
                                <span class="required-icon tooltip" title=" This field is required, it cannot be blank.">Required</span> 
                            </div>
                            <div class="field required">
                                <label>Departure City</label> 
                                <select name="departure_city">
                                    <c:forEach items="${locationList}" var="loc">
                                        <c:if test="${loc.id == item.departure_city}">
                                            <option selected="selected" value="${loc.id}">${loc.name}</option>
                                        </c:if>
                                        <option value="${loc.id}">${loc.name}</option>
                                    </c:forEach>
                                </select>
                            </div>
                            <div class="field required">
                                <label>Departure Time</label> 
                                <input type="text" class="text" name="departure_time" id="departure_time" value="${item.departure_time}"/> 
                                <span class="required-icon tooltip" title=" This field is required, it cannot be blank.">Required</span> 
                            </div>
                            <div class="field required">
                                <label>Arrival City</label> 
                                <select name="arrival_city">
                                    <c:forEach items="${locationList}" var="loc">
                                        <c:if test="${loc.id == item.arrival_city}">
                                            <option selected="selected" value="${loc.id}">${loc.name}</option>
                                        </c:if>
                                        <option value="${loc.id}">${loc.name}</option>
                                    </c:forEach>
                                </select>
                            </div>
                            <div class="field required">
                                <label>Arrival Time</label> 
                                <input type="text" class="text" name="arrival_time" id="arrival_time" value="${item.arrival_time}"/> 
                                <span class="required-icon tooltip" title=" This field is required, it cannot be blank.">Required</span> 
                            </div>
                            <div id="buttom1">
                                <strong>
                                    <html:submit value="Update Flight" styleClass="buttom_form"/>
                                </strong>
                                <strong>    
                                    <html:cancel value="Cancel" styleClass="buttom_form"/>
                                </strong>
                            </div>
                        </fieldset>
                    </div>
                    <span class="bBR"></span>
                </div>
            </html:form>
            <!-- /Form -->
        </logic:notEmpty>	
    </div>
    <!-- /Inner Content -->
    <div class="bBottom"><div></div></div>
</div>
